﻿// Services/SalaryCalculationService.cs
using HospitalSalarySystem.Models;
using System;

namespace HospitalSalarySystem.Services
{
    /// <summary>
    /// 薪资计算服务
    /// </summary>
    public class SalaryCalculationService
    {
        /// <summary>
        /// 计算年度薪资增长
        /// </summary>
        public decimal CalculateSalaryIncrease(Employee employee)
        {
            // 基础计算逻辑（需根据实际规则完善）
            //编外人员工资 =（岗位工资+薪级工资+岗位津贴+生活补贴）×比例								

            decimal baseSalary = GetBaseSalary(employee);
            decimal allowance = GetGangweiJingtie(employee);
            decimal seniorityBonus = GetXinjiGongzi(employee);

            return (baseSalary + allowance + seniorityBonus + 670) * employee.Bili;
        }
        /// <summary>
        /// 岗位工资
        /// </summary>
        /// <param name="employee"></param>
        /// <returns></returns>
        private decimal GetBaseSalary(Employee employee)
        {
            // 根据岗位等级确定岗位工资
            string switchstr = employee.PositionLevel;
            if (employee.IsNurse)
            {
                switchstr = "护理" + switchstr;
            }

            return switchstr switch
            {
                "专技三级" => 4460m,
                "专技四级" => 4080m,
                "专技五级" => 3420m,
                "专技六级" => 2950m,
                "专技七级" => 2740m,
                "专技八级" => 2370m,
                "专技九级" => 2130m,
                "专技十级" => 1940m,
                "专技十一级" => 1740m,
                "专技十二级" => 1720m,
                "专技十三级" => 1585m,
                "护理专技三级" => 5126m,
                "护理专技四级" => 4488m,
                "护理专技五级" => 3762m,
                "护理专技六级" => 3245m,
                "护理专技七级" => 3014m,
                "护理专技八级" => 2607m,
                "护理专技九级" => 2343m,
                "护理专技十级" => 2134m,
                "护理专技十一级" => 1914m,
                "护理专技十二级" => 1892m,
                "护理专技十三级" => 1744m,
                "七级职员" => 2240m,
                "八级职员" => 1960m,
                "九级职员" => 1680m,
                "十级职员" => 1585m,
                "技术工三级" => 1780m,
                "技术工四级" => 1680m,
                "技术工五级" => 1580m,
                "普通工" => 1560m,
                _ => 0m

            };
        }
        /// <summary>
        /// 岗位津贴
        /// </summary>
        /// <param name="employee"></param>
        /// <returns></returns>
        private decimal GetGangweiJingtie(Employee employee)
        {
            // 根据岗位等级确定岗位津贴
            string switchstr = employee.PositionLevel;
            if (employee.IsNurse)
            {
                switchstr = "护理" + switchstr;
            }

            return switchstr switch
            {
                "专技三级" => 1746m,
                "专技四级" => 1552m,
                "专技五级" => 1392m,
                "专技六级" => 1263m,
                "专技七级" => 1119m,
                "专技八级" => 1013m,
                "专技九级" => 887m,
                "专技十级" => 778m,
                "专技十一级" => 688m,
                "专技十二级" => 598m,
                "专技十三级" => 396m,
                "护理专技三级" => 1746m,
                "护理专技四级" => 1552m,
                "护理专技五级" => 1392m,
                "护理专技六级" => 1263m,
                "护理专技七级" => 1119m,
                "护理专技八级" => 1013m,
                "护理专技九级" => 887m,
                "护理专技十级" => 778m,
                "护理专技十一级" => 688m,
                "护理专技十二级" => 598m,
                "护理专技十三级" => 396m,
                "七级职员" => 1003m,
                "八级职员" => 771m,
                "九级职员" => 598m,
                "十级职员" => 396m,
                "技术工三级" => 652m,
                "技术工四级" => 487m,
                "技术工五级" => 411m,
                "普通工" => 411m,

                _ => 0m

            };
        }

        /// <summary>
        /// 专技薪级工资
        /// </summary>
        /// <returns></returns>
        private decimal GetXinjiGongzi(Employee employee)
        {
            // 根据岗位等级确定专技薪级工资
            return (employee.XinJiLevel + CalculateSeniorityBonus(employee)) switch
            {
                1 => 335m,
                2 => 365m,
                3 => 395m,
                4 => 425m,
                5 => 459m,
                6 => 493m,
                7 => 530m,
                8 => 567m,
                9 => 614m,
                10 => 661m,
                11 => 713m,
                12 => 765m,
                13 => 822m,
                14 => 879m,
                15 => 941m,
                16 => 1003m,
                17 => 1070m,
                18 => 1137m,
                19 => 1209m,
                20 => 1283m,
                21 => 1357m,
                22 => 1434m,
                23 => 1516m,
                24 => 1598m,
                25 => 1680m,
                26 => 1770m,
                27 => 1860m,
                28 => 1950m,
                29 => 2040m,
                30 => 2139m,
                31 => 2238m,
                32 => 2337m,
                33 => 2436m,
                34 => 2545m,
                35 => 2654m,
                36 => 2763m,
                37 => 2875m,
                38 => 2987m,
                39 => 3099m,
                40 => 3218m,

                _ => 0m

            };
        }

        private decimal GetAllowance(Employee employee)
        {
            // 编内人员津贴计算
            if (employee.IsNurse)
            {
                return (DateTime.Now.Year - employee.EnrollmentDate.Year) * 100m;
            }
            return 0m;
        }

        /// <summary>
        /// 工龄计算（按年）
        /// </summary>
        /// <param name="employee"></param>
        /// <returns></returns>
        private decimal CalculateSeniorityBonus(Employee employee)
        {
            // 工龄计算（按年）
            int years = DateTime.Now.Year - employee.EnrollmentDate.Year;
            return years;
        }


    }
}